package com.talentech.xprober;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.util.Log;
import de.robv.android.xposed.XposedBridge;

public class Utils {

	private static final String TAG = "XProber";
	
	public static Object callProtectedMethod(Object o, String methodName)
	{
        Method protectedMethod = null;
		try {
			protectedMethod = Object.class.  
			        getDeclaredMethod(methodName);
			
			log("protectedMethod succeeded");
			
		} catch (NoSuchMethodException e1) {
			// TODO Auto-generated catch block
			log("protectedMethod failed");
			e1.printStackTrace();
			
			return null;
		}  
          
        protectedMethod.setAccessible(true);  
          
        Object result = null;
        try {
        	result = protectedMethod.invoke(o);
			log("invoke succeeded");
					
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
			
			log("invoke failed " + e2.getMessage());
		}
        
        return result;
	}

	public static void log(String s)
	{
		XposedBridge.log(s);
		Log.d(TAG, s);
	}

}
